package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Address;
import com.example.entity.RelationAddress;
import com.example.mapper.RelationAddressMapper;
import com.example.service.AddressService;
import com.example.mapper.AddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author JOYY
 * @description 针对表【wd_address】的数据库操作Service实现
 * @createDate 2023-02-04 11:49:51
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address>
        implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Autowired
    private RelationAddressMapper relationAddressMapper;

    @Override
    public boolean addAddress(Address address, String userId) {

        if (!StringUtils.isEmpty(address) && !StringUtils.isEmpty(userId)) {
            //添加地址
            int i = addressMapper.insert(address);

            //添加用户和地址关系表
            RelationAddress relationAddress = new RelationAddress();
            relationAddress.setAddId(address.getAddId());
            relationAddress.setUserId(userId);
            int insert = relationAddressMapper.insert(relationAddress);
            if (i > 0 && insert > 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }

    }
}




